package com.wanshi.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCUtil {
	
	private static ComboPooledDataSource source = new ComboPooledDataSource();
	
	
	public static DataSource getSource(){
		return source;
	}
	
	public static Connection getConn() throws ClassNotFoundException, SQLException{
		return source.getConnection();
	}
	
	public static void closeRes(ResultSet rs,Statement statement,Connection conn){
		try {
			if(rs != null){
				rs.close();
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try {
			if(statement != null){
				statement.close();
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try {
			if(conn != null){
				conn.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
